﻿using System;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
using Texfina.Core.Common;  
using Texfina.Core.Web;
using Texfina.Common.Mg;
using Texfina.Core.Data;  
using Texfina.Entity.Rh;
using Texfina.Entity.Mg;
using Texfina.Entity.Sy;
using RHBOQry = Texfina.BOQry.Rh;
using MGBOQry = Texfina.BOQry.Mg;

namespace RH
{
   public partial class wfPeriodoPlani : SearchPage 
   {
       //public const int _GRDLIST_STANULADO = 5;
    
      protected void Page_Load(object sender, EventArgs e)
      {
                       
         this.LoadInitialSettings();
         if(this.IsPostBack){
            this.LoadInPostBack();
            return;
         } 

         this.LoadData();
         SearchData();

      }

      public override void LoadInitialSettings()
      {
         Label lbl = (Label) this.Master.FindControl("lblTitle");
         lbl.Text = "Periodo Planilla";
         this.Page.Form.DefaultButton = bttSearch.UniqueID;
      }
      public override void LoadListControls()
      {
         ETablaGenDet objEDet = new ETablaGenDet();
         MGBOQry.ITablaGen objBOI = (MGBOQry.ITablaGen)WCFHelper.GetObject<MGBOQry.ITablaGen>(typeof(MGBOQry.TablaGen));

         objEDet.IdTabla = ConstMultitabla.MES;
         DataTable dt = objBOI.GetDetailByList(objEDet);
         WebHelper.LoadListControl(ddlIdmes, dt, "dsDescrip", "idCodigo", true, true);

         WebHelper.ListControlSetValue(ddlIdmes,DateTime.Now.Month.ToString("000"));

         objEDet.IdTabla = ConstMultitabla.FORMA_PAGO;
         dt = objBOI.GetDetailByList(objEDet);
         WebHelper.LoadListControl(ddlIdForPago, dt, "dsDescrip", "idCodigo");

      }

      public override void SearchData()
      {

         EPeriodoPlaniBandeja objE = new EPeriodoPlaniBandeja();

         objE.IdPeriodo = Session[ConstSessionVar.PERIODO].ToString();
         objE.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString();  

         if (this.ddlIdForPago.SelectedValue == "")
            objE.IdForPago = null;
         else
            objE.IdForPago = this.ddlIdForPago.SelectedValue;

         if (this.txtidPlanilla.Text == "")
            objE.IdPlanilla  = null;
         else
            objE.IdPlanilla = this.txtidPlanilla.Text;

         if (this.txtDsPlanilla.Text == "")
            objE.DsPlanilla = null;
         else
            objE.DsPlanilla = this.txtDsPlanilla.Text;

         if (this.ddlIdmes.SelectedValue == "")
            objE.Idmes = null;
         else
            objE.Idmes = this.ddlIdmes.SelectedValue;

         DataTable dt = new DataTable();

         if (Request.QueryString["IdPlaniFilter"] != null)
             objE.IdPlanillaFilter = Request.QueryString["IdPlaniFilter"].ToString();
         else
             objE.IdPlanillaFilter = null;

         if (Request.QueryString["IdPersonal"] == null)
         {
            IBOQuery objBO = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(RHBOQry.PeriodoPlani));
            dt = objBO.GetByCriteria(objE);
         }
         else 
         {
             if (Request.QueryString["IdForPago"] != null)
             {
                 WebHelper.ListControlSetValue(ddlIdForPago, Request.QueryString["IdForPago"].ToString());
                 objE.IdForPago = Request.QueryString["IdForPago"].ToString();
                 ddlIdForPago.Enabled = false;
             }
            objE.IdPersonal = Request.QueryString["IdPersonal"].ToString();
            RHBOQry.IPeriodoPlani objBO = (RHBOQry.IPeriodoPlani)WCFHelper.GetObject<RHBOQry.IPeriodoPlani>(typeof(RHBOQry.PeriodoPlani));
            dt = objBO.GetByXPersonal(objE);
         }

         this.GridSetDataBinding(grdList, dt);

      }

      protected void grdList_RowCreated(object sender, GridViewRowEventArgs e)
      {
         if (e.Row.RowType == DataControlRowType.DataRow)
         {
            e.Row.Attributes.Add("ondblclick", "rowDblClick(" + e.Row.RowIndex.ToString() + ")");
         }
      }

      protected void bttOk_Click(object sender, EventArgs e)
      {
          this.SearchData();
      }
   }
}